package com.shuai.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.shuai.stickynote.LeftMenu;
import com.shuai.stickynote.R;

import java.util.ArrayList;

public class LeftMenuAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<LeftMenu> data;
    private int selectItem = -1;

    public int getSelectItem() {
        return selectItem;
    }

    public LeftMenuAdapter(Context context, ArrayList<LeftMenu> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = View.inflate(context, R.layout.item_menu,null);
        ImageView v_icon = convertView.findViewById(R.id.item_img);
        TextView v_name = convertView.findViewById(R.id.item_content);
        ImageView v_right = convertView.findViewById(R.id.right_img);
//        ListView v_listView = convertView.findViewById(R.id.second_menu_list);
        v_icon.setImageResource(data.get(position).getIcon());
        v_name.setText(data.get(position).getName());

        if (data.get(position).isHaveMore()){
            v_right.setVisibility(View.VISIBLE);
//            SecondMenuAdapter adapter = new SecondMenuAdapter(context,new String[]{"哈哈","嘿嘿"});
//            v_listView.setAdapter(adapter);
        }else {
            v_right.setVisibility(View.GONE);
//            v_listView.setVisibility(View.GONE);
        }
        if (position == selectItem){
            convertView.setBackground(new ColorDrawable(Color.parseColor("#e6e6e6")));
        }else {
            convertView.setBackground(new ColorDrawable(Color.parseColor("#ffffff")));
        }
        return convertView;
    }

    public void setItemSelected(int selecteItem){
        this.selectItem = selecteItem;
    }
}
